package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Honor;
import com.ruoyi.system.service.IHonorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 荣誉称号Controller
 * 
 * @author wei&wu
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/system/honor")
public class HonorController extends BaseController
{
    @Autowired
    private IHonorService honorService;

    /**
     * 查询荣誉称号列表
     */
    @PreAuthorize("@ss.hasPermi('system:honor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Honor honor)
    {
        startPage();
        List<Honor> list = honorService.selectHonorList(honor);
        return getDataTable(list);
    }

    /**
     * 导出荣誉称号列表
     */
    @PreAuthorize("@ss.hasPermi('system:honor:export')")
    @Log(title = "荣誉称号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Honor honor)
    {
        List<Honor> list = honorService.selectHonorList(honor);
        ExcelUtil<Honor> util = new ExcelUtil<Honor>(Honor.class);
        util.exportExcel(response, list, "荣誉称号数据");
    }

    /**
     * 获取荣誉称号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:honor:query')")
    @GetMapping(value = "/{honorId}")
    public AjaxResult getInfo(@PathVariable("honorId") String honorId)
    {
        return success(honorService.selectHonorByHonorId(honorId));
    }

    /**
     * 新增荣誉称号
     */
    @PreAuthorize("@ss.hasPermi('system:honor:add')")
    @Log(title = "荣誉称号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Honor honor)
    {
        return toAjax(honorService.insertHonor(honor));
    }

    /**
     * 修改荣誉称号
     */
    @PreAuthorize("@ss.hasPermi('system:honor:edit')")
    @Log(title = "荣誉称号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Honor honor)
    {
        return toAjax(honorService.updateHonor(honor));
    }

    /**
     * 删除荣誉称号
     */
    @PreAuthorize("@ss.hasPermi('system:honor:remove')")
    @Log(title = "荣誉称号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{honorIds}")
    public AjaxResult remove(@PathVariable String[] honorIds)
    {
        return toAjax(honorService.deleteHonorByHonorIds(honorIds));
    }
}
